package parcomb

import testaux.*

fun f_list(): (List<Char>) -> Pair<Pair<List<List<Function>>, List<Char>>?, Error?> = many1(lstrip(func_decl()))
fun func_list2(): (List<Char>) -> Pair<Pair<List<FunctionList>, List<Char>>?, Error?> = {(s: List<Char>) ->
    val ans = f_list()(s)
    if (isFailed(ans))
        failed<Char, FunctionList>(getError(ans))
    else {
        val fl = getResult(ans)[0].foldr<Function, FunctionList?>({(x1: Function, x2: FunctionList?) -> FunctionList(x1, x2)}, null)
        single3(fl!!, getStream(ans), null)
    }
}

fun func_decl2list() =
        bind(func_decl(),   {(f: Function) ->
            result(FunctionList(f, null))
        })
